package com.base.utils

import android.content.Context
import android.os.Looper
import android.widget.Toast

/**
 * by      qin
 * desc    toast工具类
 * created 2021年3月18日17:37:05
 */
class ToastUtils {
    companion object {
        fun showTost(mContext: Context?, tost: String?) {
            try {
                Toast.makeText(mContext, tost, Toast.LENGTH_SHORT).show()
            } catch (e: Exception) {
                //解决在子线程中调用Toast的异常情况处理
                Looper.prepare()
                Toast.makeText(mContext, tost, Toast.LENGTH_SHORT).show()
                Looper.loop()
            }
        }

        fun showTost(mContext: Context, tost: Int) {
            try {
                Toast.makeText(mContext, mContext.getString(tost), Toast.LENGTH_SHORT).show()
            } catch (e: java.lang.Exception) {
                //解决在子线程中调用Toast的异常情况处理
                Looper.prepare()
                Toast.makeText(mContext, tost, Toast.LENGTH_SHORT).show()
                Looper.loop()
            }
        }

        fun showTostLong(mContext: Context?, tost: String?) {
            try {
                Toast.makeText(mContext, tost, Toast.LENGTH_LONG).show()
            } catch (e: Exception) {
                //解决在子线程中调用Toast的异常情况处理
                Looper.prepare()
                Toast.makeText(mContext, tost, Toast.LENGTH_LONG).show()
                Looper.loop()
            }
        }

        fun showTostLong(mContext: Context, tost: Int) {
            try {
                Toast.makeText(mContext, mContext.getString(tost), Toast.LENGTH_LONG).show()
            } catch (e: Exception) {
                //解决在子线程中调用Toast的异常情况处理
                Looper.prepare()
                Toast.makeText(mContext, tost, Toast.LENGTH_LONG).show()
                Looper.loop()
            }
        }
    }

}